home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / PRGMANIA / XA_6S / SOURCE / NEW_CLNT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-17  |  3.9 KB  |  154 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <FILESYS.H>
  9. #include <OSBIND.H>
  10. #include <MINTBIND.H>
  11. #include <stdio.h>
  12. #include <memory.h>
  13. #include "XA_DEFS.H"
  14. #include "XA_TYPES.H"
  15. #include "XA_GLOBL.H"
  16. #include "C_WINDOW.H"
  17. #include "SYSTEM.H"
  18. #include "RESOURCE.H"
  19. #include "events.h"
  20. #include "DESKTOP.H"
  21. #include "RECTLIST.H"
  22.  
  23. /*
  24.     Open the clients comms pipe in response to an XA_NEW_CLIENT message
  25. */
  26. unsigned long XA_new_client(short clnt_pid,AESPB *pb)
  27. {
  28.     char pipe_name[50];
  29.     char fmt[]="u:\\pipe\\XaClnt.%d\0";
  30.     short f;
  31.     XA_CLIENT *client=Pid2Client(clnt_pid);
  32.  
  33.     if (!client->clnt_pipe_rd)    /* If this occurs, then we've got a problem */
  34.     {
  35.         DIAGS(("New Client - Error: client pipe does not exist yet?\n"));
  36.         /* PANIC - opening a global handle won't help because global
  37.             handles can't be used in an Fselect mask... */
  38.         return XAC_BLOCK ;
  39.     }
  40.  
  41.     if (!client->clnt_pipe_wr)
  42.     {
  43.         sprintf(pipe_name,fmt,clnt_pid);                        /* Open the clients reply pipe for writing to */
  44.         client->clnt_pipe_wr=(int)Fopen(pipe_name,O_RDWR);        /* Kernals end of pipe*/
  45.         client_handle_mask|=1L<<(client->clnt_pipe_wr);
  46.     }
  47.     
  48.     client->std_menu=ResourceTree(system_resources,SYSTEM_MENU);
  49.  
  50.     sprintf(client->name,"Foreign client ?");
  51.     sprintf(client->proc_name,"XACLIENT");
  52.  
  53.     for(f=0; ((client->cmd_name[f]!='\0')&&(client->cmd_name[f]!='.'))&&(f<8); f++)
  54.         client->proc_name[f]=client->cmd_name[f];
  55.     
  56.     for(; f<8; f++)
  57.         client->proc_name[f]=' ';
  58.  
  59.     client->proc_name[8]='\0';
  60.  
  61.     return XAC_DONE;    /* We now unblock the client, 'coz we've setup our end */
  62. }
  63.  
  64. /*
  65.     Close down the client reply pipe in response to an XA_CLIENT_EXIT message
  66.     - also does a tidy-up and delete's all the clients windows (in case some untidy programs
  67.       fail to close them for themselves).
  68.     - also disposes of any pending messages.
  69. */
  70. unsigned long XA_client_exit(short clnt_pid,AESPB *pb)
  71. {
  72.     XA_WINDOW *wl,*nwl;
  73.     XA_AESMSG_LIST *nm,*dnm;
  74.     XA_WIDGET_TREE *menu_bar=(XA_WIDGET_TREE*)(root_window->widgets[XAW_MENU].stuff);
  75.     XA_CLIENT *client=Pid2Client(clnt_pid);
  76.     
  77. /* Go through and check that all windows belonging to this client are */
  78. /* closed and deleted (in case of sloppy programming). */
  79.     for(wl=window_list; wl; wl=nwl)
  80.     {
  81.         nwl=wl->next;
  82.         
  83.         if ((wl->owner==clnt_pid)&&(wl!=root_window))
  84.         {
  85.             close_window(wl);
  86.             delete_window(wl);
  87.         }
  88.     }
  89.  
  90. /* Dispose of any pending messages for the client */
  91.     for(nm=client->msg; nm;)
  92.     {
  93.         dnm=nm;
  94.         nm=nm->next;
  95.         free(dnm);
  96.     }
  97.     client->msg=NULL;
  98.  
  99. /* If the client forgot to remove it's menu bar, better do it now */
  100.     if (menu_bar->tree==client->std_menu)
  101.     {
  102.         menu_bar->tree=ResourceTree(system_resources,SYSTEM_MENU);
  103.         menu_bar->owner=AESpid;
  104.         v_hide_c(V_handle);
  105.         display_non_topped_window(root_window,NULL); 
  106.         v_show_c(V_handle,1);
  107.     }
  108.  
  109. /* Did the exiting app forget to remove a custom desktop? */
  110.     if ((desktop==client->desktop)&&(desktop!=ResourceTree(system_resources,DEF_DESKTOP)))
  111.     {
  112.         set_desktop(Pid2Client(menu_bar->owner)->desktop);
  113.  
  114.         v_hide_c(V_handle);
  115.         display_non_topped_window(root_window,NULL);
  116.         v_show_c(V_handle,1);
  117.     }
  118.  
  119. #if 0
  120. /* If the client forgot to free it's resources, we do it for them. */
  121.     if (client->std_resource)
  122.     {
  123.         FreeResources(client->std_resource);
  124.         clients->std_resource=NULL;
  125.     }
  126. #endif
  127.  
  128.     /* Free command tail and name *only if* they were malloced: */
  129.     if (client->cmd_tail != dummy_cmd_tail)
  130.         free(client->cmd_tail);
  131.     if (client->cmd_name != dummy_cmd_name)
  132.         free(client->cmd_name);
  133.  
  134.     client->std_resource=NULL;
  135.     client->cmd_tail=(char*)dummy_cmd_tail;
  136.     client->cmd_name=(char*)dummy_cmd_name;
  137.     client->zen=NULL;
  138.     client->desktop=NULL;
  139.     
  140.     if (update_lock==clnt_pid)                    /* unlock mouse & screen */
  141.     {
  142.         update_lock=FALSE;
  143.         update_cnt=0;
  144.     }
  145.  
  146.     if (mouse_lock==clnt_pid)
  147.     {
  148.         mouse_lock=FALSE;
  149.         mouse_cnt=0;
  150.     }
  151.  
  152.     return XAC_DONE;    /* Closed down, let the client move on & exit */
  153. }
  154.